package com.dongdongshop.serviceimpl;

import com.alibaba.dubbo.config.annotation.Service;
import com.dongdongshop.mapper.TbTypeTemplateMapper;
import com.dongdongshop.pojo.TbTypeTemplate;
import com.dongdongshop.pojo.TbTypeTemplateExample;
import com.dongdongshop.service.TemplateService;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

@Service
@org.springframework.stereotype.Service
public class TemplateServiceImpl implements TemplateService {
    @Autowired
    private TbTypeTemplateMapper tbTypeTemplateMapper;
    //查询模板管理所有信息
    @Override
    public List<TbTypeTemplate> findAll(String name) {
        TbTypeTemplateExample tte = new TbTypeTemplateExample();
        TbTypeTemplateExample.Criteria criteria = tte.createCriteria();
        criteria.andNameLike("%" + name + "%");
        List<TbTypeTemplate> tbTypeTemplates = tbTypeTemplateMapper.selectByExample(tte);
        return tbTypeTemplates;
    }

    //增加模板管理
    @Override
    public Boolean insertTemplate(TbTypeTemplate tbTypeTemplate) {
        try {
            int i = tbTypeTemplateMapper.insertSelective(tbTypeTemplate);
            if (i > 0){
                return true;
            }
            return false;
        } catch (Exception e) {
            e.printStackTrace();
            throw e;
        }

    }

    //查询当前模板管理对象
    @Override
    public TbTypeTemplate selectById(Long id) {
        TbTypeTemplate tbTypeTemplate = tbTypeTemplateMapper.selectByPrimaryKey(id);
        return tbTypeTemplate;
    }

    //修改
    @Override
    public Boolean updateTemplate(TbTypeTemplate tbTypeTemplates) {
        try {
            int i = tbTypeTemplateMapper.updateByPrimaryKeySelective(tbTypeTemplates);
            if (i>0){
                return true;
            }
            return false;
        } catch (Exception e) {
            e.printStackTrace();
            throw e;
        }
    }

    //删除
    @Override
    public Boolean deleteById(Long[] ids) {
        try {
            int j = 0;
            for (int i = 0; i < ids.length; i++) {
                j = tbTypeTemplateMapper.deleteByPrimaryKey(ids[i]);
            }
            if (j>0){
                return true;
            }
            return false;
        } catch (Exception e) {
            e.printStackTrace();
            throw e;
        }
    }
}
